package com.orion.schdule;

import com.orion.util.SmallTool;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 *  spring的schedule线程池默认只有一个线程
 *
 *  多个定时任务指定间隔执行
 *
 * @author Administrator
 */
@Component
@ConditionalOnProperty(value = "schedule.multiScheduleTask",havingValue = "true")
public class MultiScheduleTask {

    /**
     * 每隔2s执行一次
     */
    @Scheduled(cron = "0/2 * * * * ? ")
    public void JustScheduleForA() {
        SmallTool.printTimeAndThread("begin Just Schedule Task A ");
        SmallTool.sleepMillis(4000);
        SmallTool.printTimeAndThread("end Just Schedule Task A  -------");
    }

    /**
     * 每隔2s执行一次
     */
    @Scheduled(cron = "0/2 * * * * ? ")
    public void JustScheduleForB() {
        SmallTool.printTimeAndThread("begin Just Schedule Task B ");
        SmallTool.sleepMillis(4000);
        SmallTool.printTimeAndThread("end Just Schedule Task B -------");
    }

    /**
     * A、B都没有睡眠的时候
     *
     1644735380007	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644735380007	|	30	|	scheduling-1	|	begin Just Schedule Task B
     1644735382009	|	30	|	scheduling-1	|	begin Just Schedule Task B
     1644735382010	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644735384004	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644735384004	|	30	|	scheduling-1	|	begin Just Schedule Task B
     1644735386002	|	30	|	scheduling-1	|	begin Just Schedule Task B
     1644735386002	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644735388001	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644735388003	|	30	|	scheduling-1	|	begin Just Schedule Task B

     B睡秒4s，超过间隔时间，A都会等到完B执行，它再执行（换A睡眠也是同理）
     1644735544003	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644735548006	|	30	|	scheduling-1	|	end Just Schedule Task A
     1644735548007	|	30	|	scheduling-1	|	begin Just Schedule Task B
     1644735550015	|	30	|	scheduling-1	|	begin Just Schedule Task B
     1644735550016	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644735554024	|	30	|	scheduling-1	|	end Just Schedule Task A
     1644735554025	|	30	|	scheduling-1	|	begin Just Schedule Task B
     1644735556015	|	30	|	scheduling-1	|	begin Just Schedule Task B
     1644735556015	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644735560026	|	30	|	scheduling-1	|	end Just Schedule Task A
     1644735560027	|	30	|	scheduling-1	|	begin Just Schedule Task B

     各自都睡眠4s，都会等待对方执行完，自己再执行，好似间隔时间等于失效

     1644736028021	|	32	|	scheduling-1	|	begin Just Schedule Task B
     1644736032029	|	32	|	scheduling-1	|	end Just Schedule Task B
     1644736032029	|	32	|	scheduling-1	|	begin Just Schedule Task A
     1644736036032	|	32	|	scheduling-1	|	end Just Schedule Task A
     1644736036033	|	32	|	scheduling-1	|	begin Just Schedule Task B
     1644736040045	|	32	|	scheduling-1	|	end Just Schedule Task B
     1644736040046	|	32	|	scheduling-1	|	begin Just Schedule Task A
     1644736044047	|	32	|	scheduling-1	|	end Just Schedule Task A
     1644736044048	|	32	|	scheduling-1	|	begin Just Schedule Task B
     1644736048050	|	32	|	scheduling-1	|	end Just Schedule Task B
     */
}
